﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Design.Kernel.IO
{
    /// <summary>
    /// Factory for the concret file loader
    /// </summary>
    public static class FileLoaderFactory
    {
        static Dictionary<string,FileLoader> extensionToTypeRelation = new Dictionary<string,FileLoader>(StringComparer.InvariantCultureIgnoreCase);

        /// <summary>
        /// Registers the type responsable for the given extension loading
        /// </summary>
        /// <param name="fileExtension">File extension</param>
        /// <param name="concreteFileLoader">Concrete FileLoader class implementation repsonsable for the loading of the file with the spcified extension.</param>
        public static void RegisterConcreteFileLoader(string fileExtension, FileLoader concreteFileLoader)
        {
            extensionToTypeRelation[fileExtension] = concreteFileLoader;
        }


        /// <summary>
        /// Returns the concrete file object responsable for the specified extension
        /// </summary>
        /// <param name="fileExtension"></param>
        /// <returns></returns>
        public static FileLoader GetConcreteFileLoader(string fileExtension)
        {
            return extensionToTypeRelation[fileExtension];
        }


        /// <summary>
        /// Gets all register file extensions
        /// </summary>
        /// <returns></returns>
        public static string[] GetAllRegisterExtensions()
        {
           return extensionToTypeRelation.Keys.ToList<string>().ToArray<string>();
        }
    }
}
